import { Component, OnInit, ChangeDetectionStrategy, Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { ajax } from 'rxjs/ajax';
import { map } from 'rxjs/operators'

@Injectable()
class wikiService {
  readonly url = 'https://zh.wikipedia.org/w/api.php?action=opensearch&format=json&limit=5&origin=*&search=';
  list(keyword: string): Observable<string[]> {
    return ajax.getJSON(this.url + keyword)
  }
}

@Component({
  selector: 'app-rx-study',
  templateUrl: './rx-study.component.html',
  styleUrls: ['./rx-study.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
  providers: [wikiService]
})
export class RxStudyComponent implements OnInit {

  constructor(private wikiService: wikiService) {
    this.wikiService.list('a').subscribe(val => console.log(val));
  };

  ngOnInit(): void {

  }

}
